﻿Option Strict On
Option Explicit On
Option Infer On

Imports System
Imports GenDotNet.TemplateSupport.Strings
Imports GenDotNet.TemplateSupport
Imports GenDotNet.Task.Common

Public Class SubInfo
   Inherits MemberInfo

   Private mSubDelegate As EmptyDelegate

   Public Sub New( _
            ByVal name As String, _
            ByVal typeInfo As TypeInfo, _
            ByVal scope As Scope, _
            ByVal modifiers As MemberModifiers, _
            ByVal methodDelegate As EmptyDelegate, _
            ByVal ParamArray parameters() As ParameterInfo)
      MyBase.New(name, typeInfo, scope, modifiers, parameters)
      Me.mSubDelegate = methodDelegate
   End Sub

   Public Sub New( _
            ByVal name As String, _
            ByVal typeInfo As TypeInfo, _
            ByVal scope As Scope, _
            ByVal modifiers As MemberModifiers, _
            ByVal interfaceItem As InterfaceItemInfo, _
            ByVal methodDelegate As EmptyDelegate, _
            ByVal ParamArray parameters() As ParameterInfo)
      MyBase.New(name, typeInfo, scope, modifiers, parameters)
      Me.mSubDelegate = methodDelegate
      Me.InterfaceItems.Add(interfaceItem)
   End Sub

   Public Shared Function NewSub( _
            ByVal name As String, _
            ByVal typeInfo As TypeInfo, _
            ByVal scope As Scope, _
            ByVal methodDelegate As EmptyDelegate, _
            ByVal ParamArray parameters() As ParameterInfo) _
            As MemberInfo
      Return New SubInfo(name, typeInfo, scope, Nothing, methodDelegate, parameters)
   End Function


   Public Property SubDelegate() As EmptyDelegate
      Get
         Return mSubDelegate
      End Get
      Set(ByVal value As EmptyDelegate)
         mSubDelegate = value
      End Set
   End Property

End Class


Namespace VB
   Public Module SubInfoExtensions

      <Runtime.CompilerServices.Extension()> _
Public Function Output(ByVal info As SubInfo) As String
         Return _
<code>
   <%= info.Scope.Output.WithSpace %><%= info.Modifiers.Output.WithSpace %>Sub <%= info.Name %>(<%= info.Parameters.Output %>)<%= info.InterfaceItems.OutputDeclaration %><%= nl %>
   <%= info.SubDelegate.Invoke() %>
   End Sub
</code>.Value
      End Function

   End Module
End Namespace

Namespace CSharp
   Public Module SubInfoExtensions
      ' NOTE: Interfaces not yet implemented for C# templates

      <Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As SubInfo) As String
         Return _
<code>
   <%= info.Scope.Output %> void <%= info.Name %>(<%= info.Parameters.Output %>)
      {
   <%= info.SubDelegate.Invoke().WithSemiColons %>
      }
</code>.Value
      End Function

   End Module
End Namespace
